#include <stdio.h>

#include <sys/time.h>
#include <interface.hh>
#include <stdint.h>

int64_t get_time_duration(struct timeval *ctime, struct timeval *ltime)
 {   
    int64_t duration;
    duration = (ctime->tv_sec - ltime->tv_sec) * 1000000;
    duration += ctime->tv_usec - ltime->tv_usec;
    return duration;
}

static int test_interface()
{
    for(int i=0; i < 10; i++)
    {
       struct timeval start_time;
       struct timeval end_time;
       gettimeofday(&start_time, NULL);
        void* p_system = init_system_monitor();     
        char* str =  get_system_status(p_system);     

        printf("%s\n",str);

        gettimeofday(&end_time, NULL);

        free_system_status(str);

        close_system_monitor(p_system);

        int64_t duration = get_time_duration(&end_time,&start_time);

        printf("i is %d duration is %ld\n",i,duration);
        sleep(1);
    }
    return 0;
}
int main(int argc,char* argv[])
{
    return test_interface();
    // cJSON* cjson = cJSON_CreateObject();
    // struct timeval start_time;
    // struct timeval end_time;

    // std::vector<format_interface*> monitors;

    // monitors.push_back(new system_load());
    // monitors.push_back(new cpu_load());
    // monitors.push_back(new disk_load());
    // monitors.push_back(new memory_load());
    // monitors.push_back(new network_load());
    // monitors.push_back(new vpe_device());

    // gettimeofday(&start_time, NULL);

    // std::vector<format_interface*>::iterator it;
    // for(it=monitors.begin();it!=monitors.end();it++)
    // {
    //     cJSON_AddItemToObject(cjson, (*it)->get_name(), (*it)->to_json());        
    // }
    // char*  str = cJSON_Print(cjson);
    // printf("%s\n",str);
    // cJSON_Delete(cjson);
    // gettimeofday(&end_time, NULL);

    // int64_t duration = get_time_duration(&end_time,&start_time);

    // printf("duration is %ld\n",duration);
    return 0;
}


 

